package com.yimils.core.goods.controller;

import com.yimils.core.common.dto.RspBase;
import com.yimils.core.goods.dto.PersonAddReq;
import com.yimils.core.goods.dto.PersonUpdateReq;
import com.yimils.core.goods.serivce.PersonService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Validated
public class PersonController {
    @Resource(name = "personService")
    PersonService personService;

    @PostMapping("/person/save")
    public RspBase savePerson(@RequestBody PersonAddReq personAddReq) {
        if (personService.savePerson(personAddReq)) {
            return RspBase.OK("成功");
        }
        return RspBase.OK("失败");
    }

    @PutMapping("/person/update")
    public RspBase updatePerson(@RequestBody PersonUpdateReq personUpdateReq) {
        if (personService.updatePerson(personUpdateReq)) {
            return RspBase.OK("成功");
        }
        return RspBase.OK("失败");
    }

    @DeleteMapping("/person/delete")
    public RspBase deletePerson(List<Long> personIds) {
        if (personService.deletePerson(personIds)) {
            return RspBase.OK("成功");
        }
        return RspBase.OK("失败");
    }

    @GetMapping("/person/list")
    public RspBase listPerson() {
        RspBase rsp = RspBase.OK();
        rsp.put("data", personService.listPerson());
        return rsp;
    }
}
